<?php
require_once('util/JurisdictionSelect.inc');
require_once('util/HTMLSelect.inc');
require_once('util/Constants.inc');
require_once('util/StaticFunctions.inc');
require_once('database/ReferenceObject.inc');
require_once('database/DocumentDAO.inc');

$user_agent = $_SERVER['HTTP_USER_AGENT'];

$is_keyword_search_type_OR = true;
$keyword_arr = array();
$jurisdiction_arr = array();
$acting_agent_arr = array();
$aa_subset_arr = array();
$aa_footnote_arr = array();
$participating_agent_arr = array();
$pa_subset_arr = array();
$pa_footnote_arr = array();
$emergency_arr = array();
$timeframe_arr = array();
$action_arr = array();
$goal_arr = array();
$prescription_arr = array();
$purpose_arr = array();
$condition_arr = array();

if(isset($_POST['txt_keyword']) && trim($_POST['txt_keyword']) !== '') {
  $keyword_arr = explode(',', $_POST['txt_keyword']);
  // Trim each element
  $keyword_arr = array_map('trim', $keyword_arr);
}

if(isset($_POST['keyword_search_type'])) {
  $is_keyword_search_type_OR = $_POST['keyword_search_type'];
}

if(isset($_POST['slct_jurisdiction'])) {
  $jurisdiction_arr = $_POST['slct_jurisdiction'];
}

if(isset($_POST['slct_acting_agent'])) {
  $acting_agent_arr = $_POST['slct_acting_agent'];
}

if(isset($_POST['slct_aa_subset'])) {
  $aa_subset_arr = $_POST['slct_aa_subset'];
}

if(isset($_POST['slct_aa_footnote'])) {
  $aa_footnote_arr = $_POST['slct_aa_footnote'];
}

if(isset($_POST['slct_participating_agent'])) {
  $participating_agent_arr = $_POST['slct_participating_agent'];
}

if(isset($_POST['slct_pa_subset'])) {
  $pa_subset_arr = $_POST['slct_pa_subset'];
}

if(isset($_POST['slct_pa_footnote'])) {
  $pa_footnote_arr = $_POST['slct_pa_footnote'];
}

if(isset($_POST['slct_emergency'])) {
  $emergency_arr = $_POST['slct_emergency'];
}

if(isset($_POST['slct_timeframe'])) {
  $timeframe_arr = $_POST['slct_timeframe'];
}

if(isset($_POST['slct_action'])) {
  $action_arr = $_POST['slct_action'];
}

if(isset($_POST['slct_goal'])) {
  $goal_arr = $_POST['slct_goal'];
}

if(isset($_POST['slct_prescription'])) {
  $prescription_arr = $_POST['slct_prescription'];
}

if(isset($_POST['slct_purpose'])) {
  $purpose_arr = $_POST['slct_purpose'];
}

if(isset($_POST['slct_condition'])) {
  $condition_arr = $_POST['slct_condition'];
}

$ref_obj = new ReferenceObject($keyword_arr, $jurisdiction_arr, 
                               $acting_agent_arr, $aa_subset_arr, $aa_footnote_arr, 
                               $participating_agent_arr, $pa_subset_arr, $pa_footnote_arr,
                               $emergency_arr, $timeframe_arr, $action_arr, $goal_arr, 
                               $prescription_arr, $purpose_arr, $condition_arr);


$sql_statement = $ref_obj->get_doc_sec_inv_sql_statement();

$docDAO = new DocumentDAO();

$doc_sec_id_arr = $docDAO->select_doc_sec_ids($sql_statement);

if($doc_sec_id_arr != NULL && count($doc_sec_id_arr) > 0) {
  $sql_statement = $ref_obj->get_document_inv_sql_statement($doc_sec_id_arr); 
  
  $document_id_arr = $docDAO->select_document_ids($sql_statement);
  
  if($document_id_arr != NULL && count($document_id_arr) > 0) {
    if(count($keyword_arr) > 0) {
      $sql_statement = $ref_obj->get_document_inv_keyword_sql_statement($document_id_arr, $is_keyword_search_type_OR);
      $document_id_arr = $docDAO->select_document_ids($sql_statement);
    }
  }
 //get_document_ids_matching_search_criteria 
}

/*
 * Copyright (C) 2014 University of Pittsburgh
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
 
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo: Layout with Dijit</title>
    <link rel="stylesheet" href="css/normalize.css" />
    <link rel="stylesheet" href="css/style.css" media="screen">
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/<?php echo Constants::CURRENT_DOJO_VER; ?>/dijit/themes/claro/claro.css" media="screen">
</head>

<body class="claro">
    <!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
	<!-- basic preloader: -->
    <div id="appLayout" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design: 'headline'">
        <div class="centerPanel" data-dojo-type="dijit/layout/AccordionContainer" data-dojo-props="region: 'center', tabPosition: 'bottom'">
            <!-- Begin Seach Results Pane -->
            <div data-dojo-type="dijit/layout/AccordionPane" title="Search Results">
                <br />
                <h2 style="text-align: center;">Legal and Ethical Indicators of Adaptive Public Health System Response</h2>
                <?php 
                  print_r($_POST);
                
                ?>
                <br />
            </div>
            <div data-dojo-type="dijit/layout/AccordionPane" title="Heeh, this is a content pane">
                <?php echo $sql_statement; ?>
                <br />
                <br />
                <?php print_r($doc_sec_id_arr); ?>
            </div>
            <div data-dojo-type="dijit/layout/AccordionPane" title="This is as well" selected="true">
                Hi how are you?
                <br />
                <?php print_r($document_id_arr); ?>
            </div>
            <div data-dojo-type="dijit/layout/AccordionPane" title="This too">
                Hi how are you? .....Great, thx
            </div>
            <!-- End Search Results Panel -->
            
            <!-- Begin Document Panel -->
            <div data-dojo-type="dijit/layout/AccordionPane" title="NONE">
                
            </div>
            <!-- End Document Panel -->
            
        </div>
        <div class="edgePanel" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'top'">
            <div id="banner"><a href="http://www.pitt.edu" id="pittLogo">University of Pittsburgh</a>
                <ul>
                    <li><a href="http://www.pitt.edu" id="pitt-home">Pitt Home</a></li>	  
	                <li><a href="http://www.publichealth.pitt.edu/" id="gsph">GSPH Home</a></li>
                </ul>
            </div>
            <div id="phasys_header">
       	        <h1 style="margin: 0px;"><a href="http://www.phasys.pitt.edu">Public Health Adaptive Systems Studies&nbsp;&nbsp;</a>&nbsp;</h1>
		    </div> 
        </div>
        <div id="leftCol" class="edgePanel" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'left', splitter: true">
            Sidebar content (left)
        </div>
    </div>
    <!-- load dojo -->
    <script src="//ajax.googleapis.com/ajax/libs/dojo/<?php echo Constants::CURRENT_DOJO_VER; ?>/dojo/dojo.js"></script>
    <script>
      require(["dojo/parser", 
               "dojo/_base/connect",  
               "dijit/form/Button",
               "dijit/form/DateTextBox",
               "dijit/form/Form",
               "dijit/form/MultiSelect",
               "dijit/form/NumberTextBox",
               "dijit/form/Select",
               "dijit/form/SimpleTextarea",
               "dijit/form/ValidationTextBox",
               "dijit/layout/AccordionPane",
               "dijit/layout/AccordionContainer",
               "dijit/layout/BorderContainer", 
               "dijit/layout/ContentPane",
               "dijit/registry", 
               "dojox/form/Uploader",
               "dojox/form/uploader/FileList", 
               "dojo/domReady!"], 
               function(parser) {
                 parser.parse();
               }
      );

      
    </script>
    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
    <script>
      (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
         function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
           e=o.createElement(i);r=o.getElementsByTagName(i)[0];
           e.src='//www.google-analytics.com/analytics.js';
           r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
      ga('create','UA-XXXXX-X');ga('send','pageview');
    </script>
</body>


</html>
